package com.lantu.sys.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.lantu.common.vo.RResult;
import com.lantu.sys.entity.Score;
import com.lantu.sys.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/system/score")
@CrossOrigin
public class ScoreController {


    @Autowired
    ScoreService scoreService;

//    分页查询操作
    @GetMapping("/{pageNo}/{pageSize}")
    public RResult getAllStudentScore(@PathVariable("pageNo") Integer pageNo,
                                      @PathVariable("pageSize") Integer pageSize,
                                      Score score){
        Page<Score> pageParam = new Page<>(pageNo,pageSize);
        IPage<Score> scorePage = scoreService.getScoreByOpr(pageParam, score);
        return RResult.ok(scorePage);
    }
    //编辑或者修改学生成绩信息
    @PostMapping("/addOrUpdateStudentScore")
    public RResult addOrUpdateStudentScore(@RequestBody Score score ){
        scoreService.saveOrUpdate(score);
        return RResult.ok();
    }
//    回显
    @GetMapping("/{uid}")
    public RResult<Score> getUid(@PathVariable("uid") Integer uid){
        QueryWrapper<Score> scoreQueryWrapper = new QueryWrapper<>();
        Score uid1 = scoreService.getOne(scoreQueryWrapper.eq("uid", uid));
        return RResult.ok(uid1);
    }
//    获取成绩echarts
    @GetMapping("/score/{uid}")
    public RResult<List> getuuid(@PathVariable("uid") Integer uid){
        QueryWrapper<Score> scoreQueryWrapper = new QueryWrapper<>();
        scoreQueryWrapper.select("chinese","math","english","wuli","huaxue","shengwu","lishi","dili","zhengzhi").eq("uid",uid);
        Score one = scoreService.getOne(scoreQueryWrapper);
        System.out.println(one);
        System.out.println("测试信息："+one);
        List list= new ArrayList<>();
        list.add(one.getChinese());
        list.add(one.getMath());
        list.add(one.getEnglish());
        list.add(one.getWuli());
        list.add(one.getHuaxue());
        list.add(one.getShengwu());
        list.add(one.getLishi());
        list.add(one.getDili());
        list.add(one.getZhengzhi());
        return RResult.ok(list);
    }
//    删除
    @DeleteMapping("/del/{uid}")
    public RResult deleteById(@PathVariable("uid") Integer uid){
        QueryWrapper<Score> scoreQueryWrapper = new QueryWrapper<>();
        scoreQueryWrapper.eq("uid", uid);
        scoreService.remove(scoreQueryWrapper);
        return RResult.ok();
    }
//    获取班级
    @GetMapping("/getAllNum/{clazzname}")
    public RResult getAll(@PathVariable("clazzname") String clazzname){
        List<Score> getallnum = scoreService.getallnum(clazzname);
        return RResult.ok(getallnum);

    }
//    获取学生最高分、平均分、最低分
    @GetMapping("/getMaxNumAs/{clazzname}")
    public RResult getMaxNum(@PathVariable("clazzname") String clazzname){


        QueryWrapper<Score> scoreQueryWrapper = new QueryWrapper<>();
        QueryWrapper<Score> scoreQueryWrapper1 = new QueryWrapper<>();
        QueryWrapper<Score> scoreQueryWrapper2 = new QueryWrapper<>();
        scoreQueryWrapper.select("max(chinese)chinese","max(math)math","max(english)english","max(wuli)wuli","max(huaxue)huaxue","max(shengwu)shengwu","max(lishi)lishi","max(zhengzhi)zhengzhi","max(dili)dili")
                .eq("clazz_name",clazzname);
        scoreQueryWrapper1.select("min(chinese)chinese","min(math)math","min(english)english","min(wuli)wuli","min(huaxue)huaxue","min(shengwu)shengwu","min(lishi)lishi","min(zhengzhi)zhengzhi","min(dili)dili")
                .eq("clazz_name",clazzname);
        scoreQueryWrapper2.select("avg(chinese)chinese","avg(math)math","avg(english)english","avg(wuli)wuli","avg(huaxue)huaxue","avg(shengwu)shengwu","avg(lishi)lishi","avg(zhengzhi)zhengzhi","avg(dili)dili")
                .eq("clazz_name",clazzname);
        Score three = scoreService.getOne(scoreQueryWrapper2);
        Score two = scoreService.getOne(scoreQueryWrapper1);
        Score one= scoreService.getOne(scoreQueryWrapper);
        List produce = new ArrayList<>();
        produce.add("produce");
        produce.add("最高分");
        produce.add("最低分");
        produce.add("平均分");


//        语文
        List chinese = new ArrayList<>();
        chinese.add("语文");
        chinese.add(one.getChinese());
        chinese.add(two.getChinese());
        chinese.add(three.getChinese());
//        数学
        List math = new ArrayList<>();
        math.add("数学");
        math.add(one.getMath());
        math.add(two.getMath());
        math.add(three.getMath());
//        英语
        List english = new ArrayList<>();
        english.add("英语");
        english.add(one.getEnglish());
        english.add(two.getEnglish());
        english.add(three.getEnglish());
//        物理
        List wuli = new ArrayList<>();
        wuli.add("物理");
        wuli.add(one.getWuli());
        wuli.add(two.getWuli());
        wuli.add(three.getWuli());
//        化学
        List huaxue = new ArrayList<>();
        huaxue.add("化学");
        huaxue.add(one.getHuaxue());
        huaxue.add(two.getHuaxue());
        huaxue.add(three.getHuaxue());
//        生物
        List shengwu = new ArrayList<>();
        shengwu.add("生物");
        shengwu.add(one.getShengwu());
        shengwu.add(two.getShengwu());
        shengwu.add(three.getShengwu());
//        历史
        List lishi = new ArrayList<>();
        lishi.add("历史");
        lishi.add(one.getLishi());
        lishi.add(two.getLishi());
        lishi.add(three.getLishi());
//        地理
        List dili = new ArrayList<>();
        dili.add("地理");
        dili.add(one.getDili());
        dili.add(two.getDili());
        dili.add(three.getDili());
//        政治
        List zhengzhi = new ArrayList<>();
        zhengzhi.add("政治");
        zhengzhi.add(one.getZhengzhi());
        zhengzhi.add(two.getZhengzhi());
        zhengzhi.add(three.getZhengzhi());

        List list= new ArrayList<>();
        list.add(one.getChinese());
        list.add(one.getMath());
        list.add(one.getEnglish());
        list.add(one.getWuli());
        list.add(one.getHuaxue());
        list.add(one.getShengwu());
        list.add(one.getLishi());
        list.add(one.getDili());
        list.add(one.getZhengzhi());

        List list0= new ArrayList<>();
        list0.add(produce);
        list0.add(chinese);
        list0.add(math);
        list0.add(english);
        list0.add(wuli);
        list0.add(huaxue);
        list0.add(shengwu);
        list0.add(lishi);
        list0.add(dili);
        list0.add(zhengzhi);

        System.out.println(list0);
        return RResult.ok(list0);
    }

}
